package com.hkemmm.shop.controller;

import com.hkemmm.shop.entity.Order_detail;
import com.hkemmm.shop.service.IOrderService;
import com.hkemmm.shop.service.IOrder_DetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/orderDetail")
public class OrderDetailController {
    @Autowired
    private IOrderService orderService;
    @Autowired
    private IOrder_DetailService orderDetailService;

    @RequestMapping("/receiveGoods")
    @ResponseBody
    public String updateDetailStatus(Integer id, Integer oid, Integer uid) {
        //更改订单细节为已收货
        orderDetailService.updateStatus(id, 2);
        List<Order_detail> list = orderDetailService.selectByOrderId(oid);
        //验证订单中所有订单细节是否已收货
        Boolean isReceive = true;
        for (Order_detail oi : list) {
            if (oi.getStatus() < 2) {
                isReceive = false;
            }
        }
        if (isReceive) {
            //所有订单细节已收货，更改订单状态为已完成
            orderService.updateStatus(oid, uid, 2);
        }

        return "ok";
    }

}
